import 'package:flutter/material.dart';
import 'dart:ui' as dart_ui;
import 'package:flutter/services.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_play_android/ui/base/base_widget.dart';
import 'package:flutter_play_android/widgets/custom_view.dart';

class CustomViewScreen extends BaseWidget {
  const CustomViewScreen({Key? key}) : super(key: key);

  @override
  BaseWidgetState<BaseWidget> attachState() => _CustomViewState();
}

class _CustomViewState extends BaseWidgetState {
  dart_ui.Image? _image;

  @override
  void initState() {
    showContent();
    _loadImage("assets/images/ic_todo.png").then((res) {
      setState(() {
        _image = res;
      });
    });
    super.initState();
  }

  /// 加载图片
  Future _loadImage(String path) async {
    var data = await rootBundle.load(path);
    var codec = await dart_ui.instantiateImageCodec(data.buffer.asUint8List());
    var info = await codec.getNextFrame();
    return info.image;
  }
  @override
  AppBar attachAppBar() => AppBar(title: const Text("自定义View"));

  @override
  Widget attachContentWidget(BuildContext context) => GestureDetector(
    child: CustomPaint(
      painter: CustomView(Colors.blue, image: _image),
      // size: Size(150,300),
    ),
    onPanDown: (dragDownDetails){},
    onPanUpdate: (dragUpdateDetails){
    },
  );

  @override
  void onClickErrorWidget() {}
}
